package org.puresilk.android.util;

import android.util.Log;

/*
 * Android Log utility class.
 * @author trevor
 *
 */
public class Logger {

	// Log instance...
	// private Log logger;
	
	private static final String LOG_PRECEEDER_DEFAULT = ">> ";
	private static final String LOG_PRECEEDER_INFO = "++ ";
	private static final String LOG_PRECEEDER_DEBUG = "~~ ";
	private static final String LOG_PRECEEDER_WARN = "-- ";
	private static final String LOG_PRECEEDER_ERROR = "!! ";
	
	// initialize tag to generic Object
	private String tag = "Object";
	
	/**
	 * Default Logger constructor.
	 */
	private Logger() {
		// get a default logger..
	}
	
	/**
	 * Default log message.
	 * @param message
	 */
	public void log(String message) {
		// check loggable
		if (Log.isLoggable(getTag(), Log.VERBOSE)) {
			Log.v(getTag(),LOG_PRECEEDER_DEFAULT + message);
		}
	}
	
	/**
	 * Log info message
	 * @param message
	 */
	public void info(String message) {
		// check loggable
		if (Log.isLoggable(getTag(), Log.INFO)) {
			Log.i(getTag(),LOG_PRECEEDER_INFO + message);
		}

	}
	
	/**
	 * Log debug message
	 * @param message
	 */
	public void debug(String message) {
		// check loggable
		// TODO: When we figure out the debugging thing, 
		//       we need to set these back to debug output
		if (Log.isLoggable(getTag(), Log.INFO)) {
			Log.i(getTag(),LOG_PRECEEDER_DEBUG + message);
		}

	}
	
	/**
	 * Log warning message
	 * @param message
	 */
	public void warn(String message) {
		// check loggable
		if (Log.isLoggable(getTag(), Log.WARN)) {
			Log.w(getTag(),LOG_PRECEEDER_WARN + message);
		}

	}
	
	/**
	 * Log error message
	 * @param message
	 */
	public void error(String message) {
		// check loggable
		if (Log.isLoggable(getTag(), Log.ERROR)) {
			Log.e(getTag(),LOG_PRECEEDER_ERROR + message);
		}

	}
	
	/**
	 * Log error message
	 * @param message
	 */
	public void error(String message, Throwable e) {
		// check loggable
		if (Log.isLoggable(getTag(), Log.ERROR)) {
			Log.e(getTag(),LOG_PRECEEDER_ERROR + message,e);
		}

	}
	
	/**
	 * Get Logger instance
	 * @return
	 */
	public static Logger getInstance() {
		return new Logger();
	}
	
	/**
	 * Get Logger instance
	 * @param tagName
	 * @return
	 */
	public static Logger getInstance(String tagName) {
		Logger l = new Logger();
		l.setTag(tagName);
		return l;
	}

	/**
	 * @return the tag
	 */
	public String getTag() {
		return tag;
	}

	/**
	 * @param tag the tag to set
	 */
	public void setTag(String tag) {
		this.tag = tag;
	}
	
}
